home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Communications / pcomm / Source / s_modem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  6.5 KB  |  223 lines

  1. /*
  2.  * Display the modem setup, query for changes.  A non-zero return code
  3.  * means something was changed.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <curses.h>
  8. #include "config.h"
  9. #include "misc.h"
  10. #include "modem.h"
  11.  
  12. int
  13. modem_setup()
  14. {
  15.     WINDOW *mo_win, *newwin();
  16.     int i, j, ret_code;
  17.     static int mod_prompt();
  18.     char *ans, *str_rep(), *str_prompt(), *menu_prompt();
  19.     static void disp_modem();
  20.     extern char *v_yn[];
  21.                     /* the current modem */
  22.     j = 0;
  23.     if (modem->m_cur != -1)
  24.         j = modem->m_cur;
  25.  
  26.     mo_win = newwin(23, 80, 0, 0);
  27.  
  28.     horizontal(mo_win, 0, 0, 33);
  29.     mvwattrstr(mo_win, 0, 34, A_BOLD, "Modem Setup");
  30.     horizontal(mo_win, 0, 46, 34);
  31.                     /* display the current settings */
  32.     disp_modem(mo_win, j);
  33.     horizontal(mo_win, 19, 0, 80);
  34.     mvwattrstr(mo_win, 20, 0, A_BOLD, "OPTION ==> ");
  35.     mvwaddstr(mo_win, 20, 58, "Press <ESC> to return");
  36.     wmove(mo_win, 20, 12);
  37.     touchwin(mo_win);
  38.     wrefresh(mo_win);
  39.                     /* get the option number */
  40.     ret_code = 0;
  41.     while ((i = get_num(mo_win, 2)) != -1) {
  42.         switch (i) {
  43.             case 1:
  44.                 j = mod_prompt(mo_win);
  45.                 break;
  46.             case 2:
  47.                 if ((ans = str_prompt(mo_win, 3, 39, "Modem init string", "sent to the modem once")) != NULL) {
  48.                     modem->init[j] = str_rep(modem->init[j], ans);
  49.                     ret_code++;
  50.                 }
  51.                 break;
  52.             case 3:
  53.                 if ((ans = str_prompt(mo_win, 4, 39, "Dialing command", "")) != NULL) {
  54.                     modem->dial[j] = str_rep(modem->dial[j], ans);
  55.                     ret_code++;
  56.                 }
  57.                 break;
  58.             case 4:
  59.                 if ((ans = str_prompt(mo_win, 5, 39, "Dialing cmd suffix", "typically the <CR> character")) != NULL) {
  60.                     modem->suffix[j] = str_rep(modem->suffix[j], ans);
  61.                     ret_code++;
  62.                 }
  63.                 break;
  64.             case 5:
  65.                 if ((ans = str_prompt(mo_win, 6, 39, "Hang up string", "")) != NULL) {
  66.                     modem->hang_up[j] = str_rep(modem->hang_up[j], ans);
  67.                     ret_code++;
  68.                 }
  69.                 break;
  70.             case 6:
  71.                 if ((ans = menu_prompt(mo_win, 7, 39, "Auto Baud detect", v_yn)) != NULL) {
  72.                     modem->auto_baud[j] = *ans;
  73.                     ret_code++;
  74.                 }
  75.                 break;
  76.             case 7:
  77.                 if ((ans = str_prompt(mo_win, 8, 39, "300 baud connect string", "")) != NULL) {
  78.                     modem->con_3[j] = str_rep(modem->con_3[j], ans);
  79.                     ret_code++;
  80.                 }
  81.                 break;
  82.             case 8:
  83.                 if ((ans = str_prompt(mo_win, 9, 39, "1200 baud connect string", "")) != NULL) {
  84.                     modem->con_12[j] = str_rep(modem->con_12[j], ans);
  85.                     ret_code++;
  86.                 }
  87.                 break;
  88.             case 9:
  89.                 if ((ans = str_prompt(mo_win, 10, 39, "2400 baud connect string", "")) != NULL) {
  90.                     modem->con_24[j] = str_rep(modem->con_24[j], ans);
  91.                     ret_code++;
  92.                 }
  93.                 break;
  94.             case 10:
  95.                 if ((ans = str_prompt(mo_win, 11, 39, "4800 baud connect string", "")) != NULL) {
  96.                     modem->con_48[j] = str_rep(modem->con_48[j], ans);
  97.                     ret_code++;
  98.                 }
  99.                 break;
  100.             case 11:
  101.                 if ((ans = str_prompt(mo_win, 12, 39, "9600 baud connect string", "")) != NULL) {
  102.                     modem->con_96[j] = str_rep(modem->con_96[j], ans);
  103.                     ret_code++;
  104.                 }
  105.                 break;
  106.             case 12:
  107.                 if ((ans = str_prompt(mo_win, 13, 39, "19200 baud connect string", "")) != NULL) {
  108.                     modem->con_192[j] = str_rep(modem->con_192[j], ans);
  109.                     ret_code++;
  110.                 }
  111.                 break;
  112.             case 13:
  113.                 if ((ans = str_prompt(mo_win, 14, 39, "No connect string 1", "")) != NULL) {
  114.                     modem->no_con1[j] = str_rep(modem->no_con1[j], ans);
  115.                     ret_code++;
  116.                 }
  117.                 break;
  118.             case 14:
  119.                 if ((ans = str_prompt(mo_win, 15, 39, "No connect string 2", "")) != NULL) {
  120.                     modem->no_con2[j] = str_rep(modem->no_con2[j], ans);
  121.                     ret_code++;
  122.                 }
  123.                 break;
  124.             case 15:
  125.                 if ((ans = str_prompt(mo_win, 16, 39, "No connect string 3", "")) != NULL) {
  126.                     modem->no_con3[j] = str_rep(modem->no_con3[j], ans);
  127.                     ret_code++;
  128.                 }
  129.                 break;
  130.             case 16:
  131.                 if ((ans = str_prompt(mo_win, 17, 39, "No connect string 4", "")) != NULL) {
  132.                     modem->no_con4[j] = str_rep(modem->no_con4[j], ans);
  133.                     ret_code++;
  134.                 }
  135.                 break;
  136.             default:
  137.                 beep();
  138.         }
  139.                     /* clear the previous prompts */
  140.         mvwaddstr(mo_win, 20, 12, "   ");
  141.         clear_line(mo_win, 21, 0, FALSE);
  142.         clear_line(mo_win, 22, 0, FALSE);
  143.         wmove(mo_win, 20, 12);
  144.         wrefresh(mo_win);
  145.     }
  146.     delwin(mo_win);
  147.     return(ret_code);
  148. }
  149.  
  150. /*
  151.  * Prompts for the modem name.  The user selects the currently showing
  152.  * choice by hitting a carriage return.  Returns the modem entry number.
  153.  * DOES NOT change the value of modem->m_cur.
  154.  */
  155.  
  156. static int
  157. mod_prompt(win)
  158. WINDOW *win;
  159. {
  160.     char ans;
  161.     int i;
  162.     void disp_modem();
  163.                     /* print prompt lines */
  164.     mvwaddstr(win, 22, 0, "Press any key to change, or <CR> to accept");
  165.     mvwaddstr(win, 21, 0, "Modem name: ");
  166.                     /* show current choice */
  167.     i = 0;
  168.     if (modem->m_cur != -1)
  169.         i = modem->m_cur;
  170.     mvwprintw(win, 21, 12, "%-30.30s", modem->mname[i]);
  171.     wmove(win, 21, 12);
  172.     wrefresh(win);
  173.                     /* show the choices one at a time */
  174.     while ((ans = wgetch(win)) != '\r') {
  175.         i++;
  176.         if (*modem->mname[i] == '\0')
  177.             i = 0;
  178.         if (ans == ESC)
  179.             return(0);
  180.         mvwprintw(win, 21, 12, "%-30.30s", modem->mname[i]);
  181.         wmove(win, 21, 12);
  182.         wrefresh(win);
  183.     }
  184.                     /* display the new values */
  185.     disp_modem(win, i);
  186.                     /* display the name in bold */
  187.     clear_line(win, 2, 39, FALSE);
  188.     wrefresh(win);
  189.     mvwattrstr(win, 2, 39, A_BOLD, modem->mname[i]);
  190.     mvwprintw(win, 2, 25, "(%d of %d) ", i+1, modem->m_entries);
  191.  
  192.     return(i);
  193. }
  194.  
  195. /*
  196.  * Show the current settings for the given modem entry number.
  197.  */
  198.  
  199. static void
  200. disp_modem(w, i)
  201. WINDOW *w;
  202. int i;
  203. {
  204.     mvwprintw(w, 2, 11, "1) Modem name ............. %-39.39s", modem->mname[i]);
  205.     mvwprintw(w, 2, 25, "(%d of %d) ", i+1, modem->m_entries);
  206.     mvwprintw(w, 3, 11, "2) Modem init string ...... %-39.39s", modem->init[i]);
  207.     mvwprintw(w, 4, 11, "3) Dialing command ........ %-39.39s", modem->dial[i]);
  208.     mvwprintw(w, 5, 11, "4) Dialing cmd suffix ..... %-39.39s", modem->suffix[i]);
  209.     mvwprintw(w, 6, 11, "5) Hang up string ......... %-39.39s", modem->hang_up[i]);
  210.     mvwprintw(w, 7, 11, "6) Auto baud detect ....... %c", modem->auto_baud[i]);
  211.     mvwprintw(w, 8, 11, "7) 300 baud connect ....... %-39.39s", modem->con_3[i]);
  212.     mvwprintw(w, 9, 11, "8) 1200 baud connect ...... %-39.39s", modem->con_12[i]);
  213.     mvwprintw(w, 10, 11, "9) 2400 baud connect ...... %-39.39s", modem->con_24[i]);
  214.     mvwprintw(w, 11, 10, "10) 4800 baud connect ...... %-39.39s", modem->con_48[i]);
  215.     mvwprintw(w, 12, 10, "11) 9600 baud connect ...... %-39.39s", modem->con_96[i]);
  216.     mvwprintw(w, 13, 10, "12) 19200 baud connect ..... %-39.39s", modem->con_192[i]);
  217.     mvwprintw(w, 14, 10, "13) No connect string 1 .... %-39.39s", modem->no_con1[i]);
  218.     mvwprintw(w, 15, 10, "14) No connect string 2 .... %-39.39s", modem->no_con2[i]);
  219.     mvwprintw(w, 16, 10, "15) No connect string 3 .... %-39.39s", modem->no_con3[i]);
  220.     mvwprintw(w, 17, 10, "16) No connect string 4 .... %-39.39s", modem->no_con4[i]);
  221.     return;
  222. }
  223.